<!DOCTYPE html>
<?php
require 'common/mysqlCommon.php';
session_start();
?>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
         <link rel="stylesheet" href="login.css">
        <!--引用js 一个是引用文件 一个是直接写在文档中-->
        <script type="text/javascript" src="js/1.js">
        </script>
        <script type="text/javascript">  
        function fun2(){
           if(document.getElementById("username1").value==""){
            alert("用户名不能为空！" );
            return false;//onsubmit的函数返回false 表单就不会提交
            }
            
            if(document.getElementById("pwd1").value==""){
                alert("密码不能为空！");
                return false;
            }
            if(document.getElementById("mycode").value==""){
                alert("验证码不能为空！");
                return false;
            }
        }
        </script>
    </head>
    <body>
       
        <?php
        // put your code here
         if(count($_POST)){
             //直接处理post请求
             $username=$_POST["username"];
             $upwd=$_POST["upwd"];
             $mycode=$_POST["mycode"];
             //strtoupper 将用户输入的验证码全部转大写，这样用户大小写验证码都可以识别
             if(strtoupper( $mycode)!=$_SESSION['captcha'])
             {
                 echo "<script>alert('验证码输入错误!!!');</script>";
             }
          
            $loginstr="select * from yonghu where username='$username' and upwd='$upwd' ";
            $result= getDataSetBySQL($loginstr);
            if(count($result)>0){
                //通过用户名和密码可以找到记录
                $_SESSION["uid"]=$result[0]["uid"];
                echo "<script>alert('登录成功！');"
                    . "location='shouye.php';</script>";
            }else{
                echo "<script>alert('用户名或者密码错误！');"
                    . "location='weblogin.php';</script>";
            }  
         }
        ?> 
       <div id="bigBox">
           <div class="inputBox">
        <form action="weblogin.php" method="POST" onsubmit="return fun2()">
            <div class="inputText">
            <input type="text" id="USERname" name="username" placeholder="用户名" value="">
            </div>
            <div class="inputText">
            <input type="password" id="pwd1" name="upwd" placeholder="密码">
            </div>
            <div class="inputText1">
                <input type="text" id="mycode" name="mycode" placeholder="验证码"><img src="codes.php"/><br/>
            </div>
            <div class="xhz">    
                <div class="qd"><input type="submit" value="确定"/></div>
                <div class="qx"><input type="reset" value="取消"/></div>
            </div>
            <div class="zc">
            <a href="zhuce.php">没有账号去注册</a>
            </div>
        </form> 
       </div>
        <br/>
      
    </body>
</html>
